/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.card;

import deatax.GameData;
import deatax.PathInfo;
import deatax.Settlement;
import deatax.Tile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

/**
 *
 * @author pson
 */
public class CardRandomPopulationPercentRadius extends CardEffect {

    @Override
    public void run(GameData data, String[] args) {
            Tile tile = data.getMap().getRandomTile();
            float[] target = data.getRender().mapToGrid(tile.getX(), tile.getY());
            data.getCamera().setTarget(target);

            int toll = Integer.parseInt(args[0]);
            int falloff = Integer.parseInt(args[1]);
            int radius = Integer.parseInt(args[2]);

            ArrayList<PathInfo> range = data.getMap().getRange(tile, radius, false, false, null);//, null, null, null, null, true, null, null, true);
            for (PathInfo pi : range) {
                Tile t = pi.getTile();
                if (t.getImprovement() != null && t.getImprovement() instanceof Settlement) {
                    int pc = toll - (pi.getCost() * falloff);
                    int change = (t.getPopulation() * pc) / 100;
                    int before = t.getPopulation();
                    int actual = t.addPopulation(change);
                    int pop = t.getPopulation();
                    data.getGui().addMessage(t.getOwner(), "Total population "
                    + ((toll >= 0) ? "grows" : "drops") + " from " + before + " to " + pop 
                    + " (" + ((toll >= 0) ? "+" : "") + actual + ")");
                }
            }
        
    }
}
